<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<base href="/"/>
<title>Insert title here</title>
	<link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
	<script type="text/javascript" src="easyui/jquery.min.js"></script>
	<script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>
	
	<script type="text/javascript">
		$(function(){
			$('#dg').datagrid({    
			    url:'admin/adminProductServlet?method=findByPage',    
			    columns:[[    
			        {field:'pid',title:'商品编号',width:100,align:'center'},    
			        {field:'pname',title:'商品名称',width:200,align:'center'},    
			        {field:'pimage',title:'图片',width:100,align:'center',
			        	formatter: function(value,row,index){
							return "<img src='"+value+"' width='40' height='40'/>";
						}
					},    
			        {field:'shop_price',title:'商城价',width:100,align:'center'},    
			        {field:'is_hot',title:'是否热门',width:100,align:'center',
			        	formatter: function(value,row,index){
							return value==1? "是":"否";
						}	
			        },    
			        {field:'xxx',title:'操作',width:100,align:'center',
			        	formatter: function(value,row,index){
							return "<a href=''>编辑</a> | <a href=''>删除</a>";
						}
	
			        }    
			    ]],
			    
			    pagination:true,  //显示分页工具条
			    pageList:[3,6,9], //设置每页条数的下拉列表
				pageNumber:1,  //初始页码
				pageSize:3,     //初始每页显示条数
				//添加工具条
				toolbar: [{
					iconCls: 'icon-add',
					handler: function(){
						$('#win').window('open');  // open a window    
					}
				}]

			});  

			
			//回显分类列表
			var url = "admin/adminCategoryServlet";
			var param = {"method":"findAll"}
			$.post(url,param,function(data){
				// data: [{"cid":1,"cname":"手机数码 "}，{"cid":2,"cname":"电脑办公"}]
				$(data).each(function(i,n){
					//得到下拉列表，并追加数据
					$("#category").append("<option value='"+n.cid+"'>"+n.cname+"</option>");
				});
			},"json");
			
			
			//添加商品操作
			$("#btn").click(function(){
				$('#saveProduct').form({    
				    url:'admin/adminProductServlet?method=addProduct',    
				    success:function(data){    
				        var json = eval("("+data+")");
				        //提示
				        $.messager.show({
							title:'我的消息',
							msg:json.msg+',消息将在3秒后关闭。',
							timeout:3000,
							showType:'slide'
						});

				        //关闭窗口
				        $('#win').window('close');  // close a window  
				        //刷新表格
				        $('#dg').datagrid('reload');    // 重新载入当前页面数据  
				    }    
				});    
				// submit the form    
				$('#saveProduct').submit();  

			});
		});
	</script>
</head>
<body>
	<table id="dg"></table> 
	
	<!-- 添加商品窗口 -->
	<div id="win" class="easyui-window" title="添加商品" style="width:600px;"   
        data-options="iconCls:'icon-save',modal:true,closed:true">   
	    <form id="saveProduct" method="post" enctype="multipart/form-data">
			<table cellSpacing="1" cellPadding="5" width="100%" align="center" bgColor="#eeeeee" style="border: 1px solid #8ba7e3" border="0">
				<tr>
					<td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
						商品名称：
					</td>
					<td class="ta_01" bgColor="#ffffff">
						<input type="text" name="pname" value="" id="userAction_save_do_logonName" class="bg"/>
					</td>
					<td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
						是否热门：
					</td>
					<td class="ta_01" bgColor="#ffffff">
						<select name="is_hot">
							<option value="1">是</option>
							<option value="0">否</option>
						</select>
					</td>
				</tr>
				<tr>
					<td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
						市场价格：
					</td>
					<td class="ta_01" bgColor="#ffffff">
						<input type="text" name="market_price" value="" id="userAction_save_do_logonName" class="bg"/>
					</td>
					<td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
						商城价格：
					</td>
					<td class="ta_01" bgColor="#ffffff">
						<input type="text" name="shop_price" value="" id="userAction_save_do_logonName" class="bg"/>
					</td>
				</tr>
				<tr>
					<td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
						商品图片：
					</td>
					<td class="ta_01" bgColor="#ffffff" colspan="3">
						<input type="file" name="pimage" />
					</td>
				</tr>
				<tr>
					<td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
						所属的分类：
					</td>
					<td class="ta_01" bgColor="#ffffff" colspan="3">
						<select id="category" name="cid">
								<option >--请选择--</option>						
						</select>
					</td>
				</tr>
				<tr>
					<td width="18%" align="center" bgColor="#f5fafe" class="ta_01">
						商品描述：
					</td>
					<td class="ta_01" bgColor="#ffffff" colspan="3">
						<textarea name="pdesc" rows="5" cols="30"></textarea>
					</td>
				</tr>
				<tr>
					<td class="ta_01" style="WIDTH: 100%" align="center"
						bgColor="#f5fafe" colSpan="4">
						<button type="button" id="btn" value="确定" onclick="addProduct()" class="button_ok">
							&#30830;&#23450;
						</button>

						<FONT face="宋体">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</FONT>
						<button type="reset" value="重置" class="button_cancel">&#37325;&#32622;</button>
					</td>
				</tr>
			</table>
		</form>    
	</div>  
		
</body>
</html>